package test2;

import org.junit.Test;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class TestJDBCTemplate {
    //1. 获取JDBCTemplate对象
    private JdbcTemplate template = new JdbcTemplate(JDBCUtil.getDatasource());

    public static void main(String[] args) {
        TestJDBCTemplate testJDBCTemplate = new TestJDBCTemplate();
        testJDBCTemplate.testselect();
    }

    /**
     * 1. 添加一条记录
     */
    @Test
    public void  addtest(){
        String sql = "insert into money(id,name,password) values(null,?,?)";
        int updated = template.update(sql, "刘欢", 123456);
        System.out.println("updated = " + updated);

    }
    //    一般我们使用BeanPropertyRowMapper实现类。可以完成数据到JavaBean的自动封装
    @Test
    public void testselect() {

        String sql = "select * from money";
        List<poketmoney_javabean> list1 = template.query(sql, new BeanPropertyRowMapper<poketmoney_javabean>(poketmoney_javabean.class));
        for (poketmoney_javabean poketmoney_javabean :list1){
            System.out.println("poketmoney_javabean = " + poketmoney_javabean);

        }


    }

}
